package org.endy.leisure.diaTracker.config

import org.endy.leisure.diaTracker.controller.WebResponse
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestControllerAdvice

@RestControllerAdvice
class CustomExceptionHandler {

    private val log = LoggerFactory.getLogger(CustomExceptionHandler::class.java)

    @ResponseBody
    @ExceptionHandler(Throwable::class)
    fun processException(exception: Exception): WebResponse<Exception> {
        log.error(exception.localizedMessage, exception)
        // 这里可以屏蔽掉后台的异常栈信息，直接返回"server error"
        return WebResponse.fail(exception.localizedMessage, 500)
    }

}